﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.SalesWeighings
{
    public class WeighTheFatHtmlHandler : IRequestHandler<WeighTheFatHtmlCommond, PageDTO<WeighTheFat>>
    {


        private readonly IBateRepository<WeighTheFat> _WeighTheFat;

        public WeighTheFatHtmlHandler(IBateRepository<WeighTheFat> weighTheFat)
        {
            _WeighTheFat = weighTheFat;
        }










        public async Task<PageDTO<WeighTheFat>> Handle(WeighTheFatHtmlCommond request, CancellationToken cancellationToken)
        {


            try
            {
                var list = new PageDTO<WeighTheFat>() { pageCount = 0, Lists = new List<WeighTheFat>(), totalCount = 0 };
                var query = _WeighTheFat.GetAll().ToList();
                list.totalCount = query.Count;
                list.pageCount = (int)Math.Ceiling(query.Count * 1.0 / request.Pagesize);
                query = query.OrderBy(x => x.MyProperty).Skip(request.pageindex-1).Take(request.Pagesize).ToList();
                list.Lists = query;

                return list;

            }
            catch (Exception)
            {

                throw;
            }





        }
    }
}
